//
//  NewsTableViewCell.m
//  UI_10_homework_CustomTableViewCell
//
//  Created by li cheng on 16/7/27.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "NewsTableViewCell.h"
#import "UIView+Frame.h"
#import "NewsNSObject.h"
@interface NewsTableViewCell()
@property (nonatomic, strong) UIImageView *newsImageView;
@property (nonatomic, strong) UILabel *newsLabel;

@end
@implementation NewsTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self buildSubviews];
    }
    return self;
}
- (void)buildSubviews{
    self.newsImageView = [[UIImageView alloc] init];
//    _newsImageView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:_newsImageView];
    self.newsLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_newsLabel];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGFloat imageViewOfMargin = 5;
    self.newsImageView.frame =
    CGRectMake(imageViewOfMargin, imageViewOfMargin, self.contentView.lc_width / 3 - imageViewOfMargin, self.contentView.lc_height - (2 * imageViewOfMargin) );
    self.newsLabel.frame = CGRectMake(self.contentView.lc_width / 3 + imageViewOfMargin, imageViewOfMargin, self.contentView.lc_width * 2 / 3 - imageViewOfMargin * 2, self.contentView.lc_height - (2 * imageViewOfMargin) );
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setNewsNSObject:(NewsNSObject *)newsNSObject{
    _newsNSObject = newsNSObject;
    _newsLabel.text = newsNSObject.label;
    NSURL *url = [NSURL URLWithString:newsNSObject.imageView];
    self.newsImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
}
@end
